import type { ShareResponse, SystemInitData, UploadResponse } from './types';
import { get, post } from '@/utils/request';

// 系统初始化接口
export const systemInit = () => get<SystemInitData>('/system/init').json();

// 文件上传接口
export function uploadFile(formData: FormData): Promise<UploadResponse> {
  const baseURL = import.meta.env.VITE_API_URL || '';
  const url = `${baseURL}/system/upload`;

  return fetch(url, {
    method: 'POST',
    body: formData,
    credentials: 'include',
  }).then(response => response.json());
}

// 获取聊天文件信息接口
export function getChatFiles(data: { image_ids: number[]; doc_ids: number[] }) {
  return post<{ image_urls: string[]; doc_urls: { filename: string; filepath: string }[] }>('/system/chat/files', data).json();
}

// 提交评分接口
export function rateMessage(data: { id: string; rate: number }) {
  return post<{ code: number; msg: string; data: any }>('/system/chat/rate', data).json();
}

// 分享页面信息接口
export function sharePageInfo(data: { title: string; url: string }) {
  return post<ShareResponse>('/system/share', data).json();
}
